package com.system.controller;

import com.system.function.object.Commodity;
import com.system.function.object.Supplier;
import com.system.function.service.CommodityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/commodity")
public class CommodityController {

    @Autowired
    private CommodityService CommodityService;


    //查询
    @RequestMapping("/s")
    @ResponseBody
    public Map<String,Object> s(Commodity Commodity) {
        List<Commodity> allCommodity = CommodityService.getAllCommodity(Commodity);
        Map<String,Object> returnMap  = new HashMap<>();
        returnMap.put("total",CommodityService.getCountCommodity(Commodity));
        returnMap.put("rows",allCommodity);
        return returnMap;
    }

    //查询
    @RequestMapping("/sGroupByWarehouse")
    @ResponseBody
    public Map<String,Object> sGroupByWarehouse(Commodity Commodity) {
        List<Commodity> allCommodity = CommodityService.groupByWarehouse(Commodity);
        Map<String,Object> returnMap  = new HashMap<>();
        returnMap.put("total",CommodityService.getCountCommodity(Commodity));
        returnMap.put("rows",allCommodity);
        return returnMap;
    }

    //查询
    @RequestMapping("/sGroupBySupplier")
    @ResponseBody
    public Map<String,Object> sGroupBySupplier(Commodity Commodity) {
        List<Commodity> allCommodity = CommodityService.groupBySupplier(Commodity);
        Map<String,Object> returnMap  = new HashMap<>();
        returnMap.put("total",CommodityService.getCountCommodity(Commodity));
        returnMap.put("rows",allCommodity);
        return returnMap;
    }
    //查询
    @RequestMapping("/sGroupByRemarks")
    @ResponseBody
    public Map<String,Object> sGroupByRemarks(Commodity Commodity) {
        List<Commodity> allCommodity = CommodityService.groupByRemarks(Commodity);
        Map<String,Object> returnMap  = new HashMap<>();
        returnMap.put("total",CommodityService.getCountCommodity(Commodity));
        returnMap.put("rows",allCommodity);
        return returnMap;
    }

    //查询
    @RequestMapping("/select")
    @ResponseBody
    public List<Commodity> select(Commodity Commodity) {
        List<Commodity> allCommodity = CommodityService.getAllCommodity(Commodity);
        return allCommodity;
    }

    //添加
    @RequestMapping("/add")
    @ResponseBody
    public String add(Commodity Commodity) {
        return CommodityService.addCommodity(Commodity);
    }

    //修改
    @RequestMapping("/up")
    @ResponseBody
    public String up(Commodity Commodity) {
        return CommodityService.updateCommodity(Commodity);
    }


    //用户删除
    @RequestMapping("/del")
    @ResponseBody
    public String del(Commodity Commodity) {
        return CommodityService.delCommodity(Commodity);
    }


}
